package test;

import common.Utils;
import org.bouncycastle.crypto.prng.drbg.DualECPoints;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Descroption
 * User:dell
 * Date:2025-09-07
 * Time:20:10
 */
public class IndexPage extends Utils {
    public static String url = "http://81.70.248.108:58080/index.html";

    public IndexPage() {
        super(url);
    }
    public void checkIndex() throws InterruptedException {
        webDriver.manage().window().maximize();
        Thread.sleep(3000);
        By article_list_board_title = By.cssSelector("#article_list_board_title");
        //等待动态生成的页面可见
        //检查导航栏
        WebDriverWait wait1 = new WebDriverWait(webDriver, Duration.ofSeconds(10));
        wait1.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[@id=\"topBoardList\"]/li/a/span[2]")));
        List<WebElement> webElements = webDriver.findElements(By.xpath("//*[@id=\"topBoardList\"]/li/a/span[2]"));
        System.out.println(webElements.size());
        for(WebElement webElement:webElements){
            System.out.print(webElement.getText()+" ");
        }
        System.out.println();
        webElements.get(0).click();
        WebDriverWait titleWait = new WebDriverWait(webDriver, Duration.ofSeconds(3));
        titleWait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#article_list_board_title")));
        String board_title  = webDriver.findElement(By.cssSelector("#article_list_board_title")).getText();
        //查看跳转之后的界面是否正确
        for (int i = 1; i < webElements.size(); i++) {
            webElements.get(i).click();
            titleWait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#article_list_board_title")));
            String jump_title = webDriver.findElement(By.cssSelector("#article_list_board_title")).getText();
            assert board_title.equals(jump_title):"跳转失败"+i;
            board_title = jump_title;

        }
        //检查论坛列表

        String btn = webDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/a[1]")).getText();
        assert !board_title.isEmpty();
        assert btn.equals("发布帖子");

        //查看跳转之后的界面是否正确
        webElements.get(0).click();
        titleWait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#article_list_board_title")));
        String initBoard_title  = webDriver.findElement(By.cssSelector("#article_list_board_title")).getText();
        webDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/a[1]")).click();
        String jump_title = webDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div/h2")).getText();
        assert !initBoard_title.equals(jump_title):"跳转失败";
    }
    /**
     * 帖子发布功能
     */


}
